﻿using DalatCooking.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DalatCooking.Core.Helper;
public partial class admin_Contact_Default : System.Web.UI.Page
{
    public int total = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected override void OnInit(EventArgs e)
    {
        BinData();
        //ddlMenuGroup.DataSource = MenuGroupManager.FindAll();
        //ddlMenuGroup.DataTextField = "Name";
        //ddlMenuGroup.DataValueField = "GroupId";
        //ddlMenuGroup.DataBind();

        //LoadParentDropDown(ddlMenuParent, 0);

        base.OnInit(e);
    }
    static int level = -1;
    public static void LoadParentDropDown(DropDownList ddl, int parentID)
    {
        level++;
        System.Text.StringBuilder appender = new System.Text.StringBuilder();
        for (int j = 0; j < level; j++)
        {
            appender.Append("&nbsp;&nbsp;&nbsp;&nbsp;");
        }
        if (level > 0)
        {
            appender.Append("|__");
        }
        List<DalatCooking.Core.Menu> list = MenuManager.FindAll().FindAll(ca => ca.ParentID == parentID && ca.IsActive == true);
        for (int i = 0; i < list.Count; i++)
        {
            ddl.Items.Add(new ListItem(HttpUtility.HtmlDecode(appender.ToString()) + list[i].Name, list[i].MenuID.ToString()));
            LoadParentDropDown(ddl, list[i].MenuID); // Goi de quy ham              
        }
        level--;
    }
    /*
    void BinMenuParent()
    {
        foreach (var item in MenusBAL.FindAll_ParentId(0))
        {
            ddlMenuParent.Items.Add(new ListItem(item.Name, item.MenuID.ToString()));
            foreach (var item1 in MenusBAL.FindAll_ParentId(item.MenuID))
            {
                ddlMenuParent.Items.Add(new ListItem("----" + item1.Name, item1.MenuID.ToString()));
            }
        }
    }
    */

    void BinData()
    {

        int pageSize = 10;
        if (Request.Cookies["postPageSize"] != null)
        {
            pageSize = ConvertObject.ToInt(Server.HtmlEncode(Request.Cookies["postPageSize"].Value));
        }
        else
        {
            pageSize = 10;
        }

        int pageNum = 1;

        if (Request.QueryString[PagingControl1.QueryStringKey] != null)
        {
            pageNum = ConvertObject.ToInt(Server.HtmlEncode(Request.QueryString[PagingControl1.QueryStringKey]));
        }
        else pageNum = 1;
        /*
        if (MenuTypeID != -1)
        {
            rpt.DataSource = MenuManager.FindAll_MenuType(pageSize, pageNum, out total, MenuTypeID);
        }
        else
        {
            rpt.DataSource = rpt.DataSource = MenusBAL.PagingSql(pageSize, pageNum, out total);
        }
        */
        rpt.DataSource = ContactManager.PagingSql(pageSize, pageNum, out total);
        rpt.DataBind();

        PagingControl1.TotalPage = total;
        PagingControl1.CurrentPage = pageNum;
        PagingControl1.PageSize = pageSize;


        PagingControl2.TotalPage = total;
        PagingControl2.CurrentPage = pageNum;
        PagingControl2.PageSize = pageSize;
    }

    protected string GetParentTitle(object obj)
    {
        MenuGroup temp = MenuGroupManager.Single(int.Parse(obj.ToString()));
        if (temp == null)
            return "";
        else
            return temp.Name;
    }

    public int Count()
    {

        return total;
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {

    }
}